package com.clouddms.service.transfer;

/**
 * 分块上传结果
 * 
 * @author Cloud-DMS Team
 * @version 1.0.0
 */
public class ChunkUploadResult {
    private boolean success;
    private String message;
    private int chunkIndex;
    private double progress;
    private String uploadId;
    private String finalFilePath;
    private UploadStatus status;

    private ChunkUploadResult() {}

    /**
     * 创建成功的分块上传结果
     */
    public static ChunkUploadResult success(int chunkIndex, double progress) {
        ChunkUploadResult result = new ChunkUploadResult();
        result.success = true;
        result.message = "分块上传成功";
        result.chunkIndex = chunkIndex;
        result.progress = progress;
        result.status = UploadStatus.UPLOADING;
        return result;
    }

    /**
     * 创建上传完成结果
     */
    public static ChunkUploadResult completed(String uploadId, String finalFilePath) {
        ChunkUploadResult result = new ChunkUploadResult();
        result.success = true;
        result.message = "文件上传完成";
        result.uploadId = uploadId;
        result.finalFilePath = finalFilePath;
        result.progress = 100.0;
        result.status = UploadStatus.COMPLETED;
        return result;
    }

    /**
     * 创建失败的上传结果
     */
    public static ChunkUploadResult failure(String message) {
        ChunkUploadResult result = new ChunkUploadResult();
        result.success = false;
        result.message = message;
        result.status = UploadStatus.FAILED;
        return result;
    }

    // Getters
    public boolean isSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public int getChunkIndex() {
        return chunkIndex;
    }

    public double getProgress() {
        return progress;
    }

    public String getUploadId() {
        return uploadId;
    }

    public String getFinalFilePath() {
        return finalFilePath;
    }

    public UploadStatus getStatus() {
        return status;
    }

    /**
     * 检查是否已完成
     */
    public boolean isCompleted() {
        return status == UploadStatus.COMPLETED;
    }

    @Override
    public String toString() {
        return String.format("ChunkUploadResult{success=%s, message='%s', progress=%.1f%%, status=%s}", 
            success, message, progress, status);
    }
}